package com.zhika.zishi;

import android.app.Application;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpClient;
import com.zhika.zishi.constant.InternetConstant;
import com.zhika.zishi.db.OperateDb;
import com.zhika.zishi.util.LogUtil;


/**
 * Created by Michael on 2015/4/5.
 */
public class MyApplication extends Application {

    private static final String TAG = "MyApplication";

    //网络请求对象
    public static AsyncHttpClient asyncHttpClient;

    //手机设备的id
    public static String device_id;

    //用户id
    public static long userId;

    //用户的token
    public static String token;

    //上下文
    private static Context context;

    //操作数据库的对象
    public static OperateDb operateDb;

    @Override
    public void onCreate() {

        //上下文
        context = getApplicationContext();

        //实例化操作数据库的对象
        operateDb = new OperateDb(context);

        TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        device_id = tm.getDeviceId();
        LogUtil.e(TAG, "device_id:" + device_id);

        //实例化网络请求的对象
        asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.addHeader("charset", InternetConstant.CHARSET);
        asyncHttpClient.addHeader("Content-Type", InternetConstant.CONTENT_TYPE);
    }

    /**
     * 吐丝
     * @param msg
     */
    public static void showToast(String msg){
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
    }
}
